package com.pmsystem.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.Building;
import com.pmsystem.pojo.BuildingShow;
import com.pmsystem.service.BuildingService;


/**
 * 
* <p>Title: BuildingController</p>  
* <p>Description:处理大楼信息的控制器 </p>  
* @author 树昌  
* @date 2019年1月21日
 */
@Controller
@RequestMapping("Information/")
public class BuildingController {

	@Autowired
	BuildingService buildingService;
	
	/**
	 * 
	 * <p>Title: addBuilding</p>  
	 * <p>Description:添加大楼信息的控制器 </p>  
	 * @author 树昌
	 * @param building
	 * @return 跳转到查询所有大楼信息的页面
	 */
	@RequestMapping(value="addbuilding" ,method=RequestMethod.POST)
	public String addBuilding(Building building) {
		
		if(building.getBlgVillageId()!=null) {
			buildingService.addBuilding(building);
			System.out.println(building.getResponsible());
			return "Information/showbuilding";
		}else {
			return "error";
		}
	}
	
	
	/**
	 * 
	 * <p>Title: showBuilding</p>  
	 * <p>Description:显示所有大楼信息的控制器 </p>  
	 * @author 树昌
	 * @return 不做跳转
	 */
	@RequestMapping(value="showbuilding",method=RequestMethod.POST)
	@ResponseBody
	public List<BuildingShow> showBuilding(String keyword, Integer startRow, Integer pageSize,Integer BID) {
		
		return buildingService.showBuilding(keyword,startRow,pageSize,BID);
	}
	
	/**
	 * 
	 * <p>Title: deleteBuilding</p>  
	 * <p>Description:删除一条大楼的记录的控制器 </p>  
	 * @author 树昌
	 * @param building
	 * 不做跳转
	 */
	@RequestMapping(value="deletebuilding" ,method=RequestMethod.POST)
	@ResponseBody
	public void deleteBuilding(Building building) {
		
		buildingService.deleteBuilding(building);
	}
	
	
	/**
	 * 
	 * <p>Title: updateBuilding</p>  
	 * <p>Description:修改一条大楼记录的控制器 </p>  
	 * @author 树昌
	 * @param building
	 * @return 跳转到显示所有大楼信息的页面
	 */
	@RequestMapping(value="updatebuilding" ,method=RequestMethod.POST)
	public String updateBuilding(Building building) {
		System.out.println(building.getBuildingId());
		
		boolean row = buildingService.updateBuilding(building);
		if(row) {
			return "Information/showbuilding";
		}else {
			return "error";
		}
	}
}
